package com.everfro.codeshare.dialog;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.ControlListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class ResultDialog extends Dialog{

	private String message;
	private String url;
	
	protected ResultDialog(Shell parentShell, String message, String url) {
		super(parentShell);
		this.message = message;
		this.url = url;
		
		
	}

	protected void createButtonsForButtonBar(Composite parent) {
		// create OK and Cancel buttons by default
		createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL,
				true);
		
	}
	
	protected Control createDialogArea(Composite parent) {
		 Composite container = (Composite) super.createDialogArea(parent);
		 GridLayout gl = new GridLayout();
	     gl.numColumns = 2;
	     container.setLayout(gl);
	     
	     Label messageLabel = new Label(container, SWT.NONE); 
	     messageLabel.setText("Message:");
	     
	     Label message = new Label(container, SWT.NONE); 
	     messageLabel.setText(this.message);
	     
	     GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
         gridData.widthHint = 200;
         
	     Text text = new Text(container, SWT.BORDER | SWT.READ_ONLY);
	     text.setLayoutData(gridData);
	     text.setText(this.url);
	     
	     Button button = new Button(container, SWT.NONE);
	     button.setText("Copy");
	     button.addSelectionListener(new SelectionListener(){

			public void widgetDefaultSelected(SelectionEvent e) {
				// TODO Auto-generated method stub
				
			}

			public void widgetSelected(SelectionEvent e) {
				// TODO Auto-generated method stub
				System.out.println("I have been slected!");
				
				Clipboard clipboard = new Clipboard(getShell().getDisplay());
			
				TextTransfer textTransfer = TextTransfer.getInstance();
				clipboard.setContents(new Object[]{url}, new Transfer[]{textTransfer});
				
				
				
				
			}

			
	    	 
	    	 
	     });
	     
		return container;
	}

}
